# -*- coding: utf-8 -*-
from utils.config import *
from utils.utils import *
import pandas as pd
import utils.MyTT as Mytt
# import logging
from utils.log import Loggers
from utils.pushService import PushService

logger = Loggers('MovingAverage')
# logger.clear()

pushSer = PushService('Macd交叉信号')

# 循环处理
for instId in config_movingAverage_instId:
    # 读取300条最新的数据
    df = loadCsvData(instId,'1D')

    # 计算指标 MACD
    df['DIF'],df['DEA'],df['MACD'] = Mytt.MACD(df['close'])
    df['cross_MACD'] = Mytt.CROSS(df['DIF'],df['DEA'])

    # 寻找金叉+连阳的信号
    df['signal'] = 0
    df.loc[(df['cross_MACD'] ==1),'signal'] = 1
    df.loc[(df['cross_MACD'] ==-1),'signal'] = -1

    # 快速计算信号近期胜率
    shenglv5,shenglv10 = getShenglv(df)

    # 取出所有满足条件的信号数据
    df_signal = df[df['signal']!=0]
    getShenglvShow(df)
    exit()
    # 拿到最后出现信号的数据
    after_signal = df_signal.iloc[-1]
    
    fangxiang = '做多' if after_signal['signal']>0 else '做空'
    signal_text = f"{instId}{fangxiang} 最近信号：{after_signal.name} 收盘价：{after_signal['close']} 5日胜率：{shenglv5}% 10日胜率：{shenglv10}%"

    exit()

    hour = getHoursPassed(after_signal.name)
    # 进行日志记录
    if hour < 8:
        # 8小时内的新信号 就可以 进行钉钉推送
        if pushSer.add_push_item(after_signal, instId,shenglv5,shenglv10):
            logger.info(signal_text)

    # 完成消息的通知
pushSer.push_message()

